<?php
class Account extends CI_Model {

	private $data = array(
		'username' => '',
		'total' => 0
    );  
    
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    

	function getAccount ($accountid, $password){
		$password = md5($password);
		$sql = sprintf("SELECT * FROM account where AccountId = %s and Password = '%s'", 
		mysql_real_escape_string($accountid), mysql_real_escape_string($password));
    
		$query = $this->db->query($sql);
		if ($query->num_rows() > 0) {
			foreach ($query->result() as $account_info) {
				$this->data['username'] = $account_info->Username;				                      
                $this->data['total']++;
			}
			return $this->data;
		} else {
			return null;
		}
	}
	
	function insertAccount($dataInsert){
		$dataInsert['DateCreated'] = date("Y-m-d");
		$dataInsert['Password'] = md5($dataInsert['Password']);
		$this->db->trans_begin();
		$this->db->insert('account', $dataInsert); 
		if ($this->db->trans_status() === FALSE){
		    $this->db->trans_rollback();
		} else {
		    $this->db->trans_commit();
		}		
	}
}
?>